package cl.uchile.sketchpad.persistance.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;

import static javax.persistence.FetchType.*;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "subject_version")
@JsonIgnoreProperties({"activities","groups","users","subject"})
public class SubjectVersion implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2766524485188425403L;

	private Integer id;
	private String name;
	private Date date;
	
	private Subject subject;
	private List<Activity> activities = new ArrayList<Activity>(0);
	private Set<User> users = new LinkedHashSet<User>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Date getDate() {
		return date;
	}
	
	public void setDate(Date date) {
		this.date = date;
	}
	
	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "subject_id")
	public Subject getSubject() {
		return subject;
	}
	
	public void setSubject(Subject subject) {
		this.subject = subject;
	}
	
	@OneToMany(fetch = LAZY, mappedBy = "subjectVersion")
	public List<Activity> getActivities() {
		return activities;
	}
	
	public void setActivities(List<Activity> activities) {
		this.activities = activities;
	}
	
	@ManyToMany(fetch = LAZY)
	@JoinTable(name = "subject_version_user",
			joinColumns = { @JoinColumn(name = "subject_version_id") },
			inverseJoinColumns = { @JoinColumn(name = "user_id") })
	@OrderBy("name")
	public Set<User> getUsers() {
		return users;
	}
	
	public void setUsers(Set<User> users) {
		this.users = users;
	}

}
